﻿/// <reference path="Scripts/jquery-1.4.2-vsdoc.js" />

/************************************************
提供一个按钮，用于员工选择控件
*************************************************/
/*var deptroot = null;
var deptinitflag = false;

document.writeln('<script language="javascript" src="' + tof_client_domain + '/tof_client/staffscript.aspx"></script>');
document.writeln('<script language="javascript" src="' + tof_client_domain + '/tof_client/deptscript.aspx"></script>');
document.writeln('<script language="javascript" src="' + tof_client_domain + '/tof_client/runtime/script/tof.js"></script>');

$(document).ready(function() {
$('.chooserContainer').each(function() {
if ($.browser.msie) // IE only
$(this).show();
});
});


function EnsureUserBuilded() {
if (!deptinitflag) {
deptinitflag = true;
InitDeptData();
}
}

function RTrim(str, sep) {
var i;
for (i = str.length - 1; i >= 0; i--) {
if (str.charAt(i) != sep)
break;
}
return str.substring(0, i + 1);
}

// 已放弃该方法，因为tof_client站点的ChooseUser.htm页面返回值仅有：userID、userName、deptID
function tofChooserUserSelect(chooser, mainbox, valuebox) {

try {
if (event.button == 2)
return;
var retVal;
var strParam;

var mainbox;
var valuebox;

EnsureUserBuilded();
//EnsureXcludeBuilded();

var inVals = new Array();
inVals[0] = chooser;
inVals[1] = arrDept;
inVals[2] = arrUser;
inVals[3] = deptroot;
inVals[4] = map;

retVal = window.showModalDialog(tof_client_domain + '/tof_client/ChooseUser.htm', inVals, 'status=no;dialogHeight:515px;dialogWidth:653px;scroll:no');

if (retVal != null) {

if (retVal[0].length == 0) retVal[0] = ";";

if (chooser.value != retVal[0]) {
valuebox.value = RTrim(retVal[0], ";");
mainbox.value = RTrim(retVal[1], ";");

chooser.value = valuebox.value;
chooser.text = mainbox.value;

eval(chooser.onchange);

// if (chooser.autopostback == "True") {
//  valuebox.fireEvent("onchange");
// }
}
chooser.defaultdepartmentid = retVal[2];
}
} catch (ex) { alert(ex.message); }
event.returnValue = false;
return false;
}
*/

(function($) {
    ///	<summary>
    ///	员工选择函数。
    ///	</summary>
    /// <param name="includeDimission" type="String">
    /// 2:离职, 1000:不存在
    /// </param>
    $.fn.staffChooser = function(includeDimission) {
        if (this.attr('userchooserinited') == 'true') return;
        this.attr('userchooserinited', 'true');
        var ismultiple = this.attr("ismultiple");
        var callback = this.attr("callback");
        var multiple = (ismultiple == "true" ? true : false);
        this.autocomplete(appRootPath  + "dept/StaffFilter?includeDimission=" + includeDimission,
        {
            delay: 200,
            minChars: 1,
            matchSubset: 1,
            matchContains: 1,
            cacheLength: 10,
            multipleSeparator: ';',
            multiple: (multiple == true),
            mustMatch: true,
            dataType: 'json',
            parse: function(data) {
                var rows = new Array();
                for (var i = 0; i < data.length; i++) {
                    rows[i] = { data: data[i], value: data[i].ID.toString(), result: data[i].Name };
                }
                return rows;
            },
            formatItem: function(row, i, max, value, term) {
                return row.Name;
            },
            scroll: false
        });

        this.result(function(event, data, formatted) {
            if (multiple == true) {
                this.focus();
                $(this).endInsPoint();
            }
            else
                this.blur();

            // 执行外部函数
            if (callback)
                eval(callback + "(event, data, formatted)");
        });

        this.focus(function() {
            if (multiple == true) {
                $(this).endInsPoint();
            } else
                this.select();
        });
    };

    ///	<summary>
    ///	员工中文名选择。
    ///	</summary>
    $.fn.staffCNChooser = function() {
        if (this.attr('userchooserinited') == 'true') return;
        this.attr('userchooserinited', 'true');
        var ismultiple = this.attr("ismultiple");
        var callback = this.attr("callback");
        var multiple = ismultiple == "true" ? true : false;
        this.autocomplete(appRootPath  + "staff/staffCNFilter",
        {
            delay: 200,
            minChars: 1,
            matchSubset: 1,
            matchContains: 1,
            cacheLength: 10,
            multipleSeparator: ';',
            multiple: multiple == true,
            mustMatch: true,
            dataType: 'json',
            parse: function(data) {
                //debugger;
                var rows = new Array();
                for (var i = 0; i < data.length; i++) {
                    rows[i] = { data: data[i], value: data[i].ID.toString(), result: data[i].Name };
                }
                return rows;
            },
            formatItem: function(row, i, max, value, term) {
                return row.Name;
            },
            scroll: false
        });
        this.result(function(event, data, formatted) {
            if (multiple == true) {
                this.focus();
                $(this).endInsPoint();
            }
            else
                this.blur();

            // 执行外部函数
            if (callback)
                eval(callback + "(event, data, formatted)");
        });
        this.focus(function() { if (multiple == true) { $(this).endInsPoint(); } else this.select(); });
    };

    ///	<summary>
    ///	员工英文名选择。
    ///	</summary>
    $.fn.staffENChooser = function() {
        if (this.attr('userchooserinited') == 'true') return;
        this.attr('userchooserinited', 'true');
        var ismultiple = this.attr("ismultiple");
        var callback = this.attr("callback");
        var multiple = ismultiple == "true" ? true : false;
        this.autocomplete(appRootPath  + "staff/staffENFilter",
        {
            delay: 200,
            minChars: 1,
            matchSubset: 1,
            matchContains: 1,
            cacheLength: 10,
            multipleSeparator: ';',
            multiple: multiple == true,
            mustMatch: true,
            dataType: 'json',
            parse: function(data) {
                //debugger;
                var rows = new Array();
                for (var i = 0; i < data.length; i++) {
                    rows[i] = { data: data[i], value: data[i].ID.toString(), result: data[i].Name };
                }
                return rows;
            },
            formatItem: function(row, i, max, value, term) {
                return row.Name;
            },
            scroll: false
        });
        this.result(function(event, data, formatted) {
            if (multiple == true) {
                this.focus();
                $(this).endInsPoint();
            }
            else
                this.blur();

            // 执行外部函数
            if (callback)
                eval(callback + "(event, data, formatted)");
        });
        this.focus(function() { if (multiple == true) { $(this).endInsPoint(); } else this.select(); });
    };

    ///	<summary>
    ///	工程师选择函数。
    ///	</summary>
    $.fn.engineerChooser = function() {
        if (this.attr('userchooserinited') == 'true') return;
        this.attr('userchooserinited', 'true');
        var ismultiple = this.attr("ismultiple");
        var callback = this.attr("callback");
        var multiple = ismultiple == "true" ? true : false;
        this.autocomplete(appRootPath  + "staff/engineerFilter",
        {
            delay: 200,
            minChars: 1,
            matchSubset: 1,
            matchContains: 1,
            cacheLength: 10,
            multipleSeparator: ';',
            multiple: multiple == true,
            mustMatch: true,
            dataType: 'json',
            parse: function(data) {
                var rows = new Array();
                for (var i = 0; i < data.length; i++) {
                    rows[i] = { data: data[i], value: data[i].ID.toString(), result: data[i].Name };
                }
                return rows;
            },
            formatItem: function(row, i, max, value, term) {
                return row.Name;
            },
            scroll: false
        });
        this.result(function(event, data, formatted) {
            if (multiple == true) {
                this.focus();
                $(this).endInsPoint();
            }
            else
                this.blur();

            // 执行外部函数
            if (callback)
                eval(callback + "(event, data, formatted)");
        });
        this.focus(function() { if (multiple == true) { $(this).endInsPoint(); } else this.select(); });
    };

    $.fn.departmentChooser = function() {
        if (this.attr('deptchooserinited') == 'true') return;
        this.attr('deptchooserinited', 'true');
        var ismultiple = this.attr("ismultiple");
        var callback = this.attr("callback");
        var multiple = ismultiple == "true" ? true : false;
        // level = this.attr("level");
        //if (!level) level = 2;
        this.autocomplete(appRootPath + "Dept/DeptFilter?levl=2",
        {
            delay: 200,
            minChars: 1,
            matchSubset: 1,
            matchContains: 1,
            cacheLength: 10,
            multipleSeparator: ';',
            multiple: multiple == true,
            mustMatch: true,
            dataType: 'json',
            parse: function(data) {
                var rows = new Array();
                for (var i = 0; i < data.length; i++) {
                    rows[i] = { data: data[i], value: data[i].ID.toString(), result: data[i].Name };
                }
                return rows;
            },
            formatItem: function(row, i, max, value, term) {
                return row.Name;
            },
            scroll: false
        });
        this.result(function(event, data, formatted) {
            if (multiple == true) {
                this.focus();
                $(this).endInsPoint();
            }
            else
                this.blur();

            // 执行外部函数
            if (callback)
                eval(callback + "(event, data, formatted)");
        });
        this.focus(function() { if (multiple == true) { $(this).endInsPoint(); } else this.select(); });
    };
    //
    $.fn.sysChooser = function() {
        if (this.attr('deptchooserinited') == 'true') return;
        this.attr('deptchooserinited', 'true');
        var ismultiple = this.attr("ismultiple");
        var callback = this.attr("callback");
        var multiple = ismultiple == "true" ? true : false;
        // level = this.attr("level");
        //if (!level) level = 2;
        this.autocomplete(appRootPath + "Dept/DeptFilter?levl=1",
        {
            delay: 200,
            minChars: 1,
            matchSubset: 1,
            matchContains: 1,
            cacheLength: 10,
            multipleSeparator: ';',
            multiple: multiple == true,
            mustMatch: true,
            dataType: 'json',
            parse: function(data) {
                var rows = new Array();
                for (var i = 0; i < data.length; i++) {
                    rows[i] = { data: data[i], value: data[i].ID.toString(), result: data[i].Name };
                }
                return rows;
            },
            formatItem: function(row, i, max, value, term) {
                return row.Name;
            },
            scroll: false
        });
        this.result(function(event, data, formatted) {
            if (multiple == true) {
                this.focus();
                $(this).endInsPoint();
            }
            else
                this.blur();

            // 执行外部函数
            if (callback)
                eval(callback + "(event, data, formatted)");
        });
        this.focus(function() { if (multiple == true) { $(this).endInsPoint(); } else this.select(); });
    };

})(jQuery);




/*

*/

